from skimage import exposure
from pydicom import dcmread


def bar(images: dict, subplot_size: tuple, wspace=None, hspace=None, mode="gray", font=None):
    from matplotlib import pyplot as plt
    from matplotlib import font_manager
    my_font = font_manager.FontProperties(fname=font)
    plt.subplots_adjust(wspace=wspace, hspace=hspace)
    for index, key in enumerate(images, start=1):
        plt.subplot(*subplot_size, index)
        plt.title(key, fontproperties=my_font)
        plt.bar(*images[key])
    plt.show()


if __name__ == '__main__':
    im_path = "../experiment_fig/I1700000"
    font_path = "C:/Windows/Fonts/simhei.ttf"
    dcm_im = dcmread(im_path)
    dcm_arr = dcm_im.pixel_array  # 2395 0
    hist_height, hist_bins = exposure.histogram(dcm_arr, normalize=True)
    cum_hist_height, cum_hist_bins = exposure.cumulative_distribution(dcm_arr)
    im_dict = {"DICOM图像直方图": [hist_bins, hist_height],
               "DICOM图像累计直方图": [cum_hist_bins, cum_hist_height]}
    bar(im_dict, (1, 2), font=font_path)
